<template>
  <div class="tips" v-show="isShow">
    <p>
      {{ tipsText }}
    </p>
  </div>
</template>

<script>
export default {
  name: "Tips",
  data() {
    return {
      isShow: false,
      tipsText: "",
      showTime: null,
    };
  },
  methods: {
    showTips(value) {
      clearTimeout(this.showTime);
      this.tipsText = value;
      this.isShow = true;
      this.showTime = setTimeout(() => {
        this.isShow = false;
        this.tipsText = "";
      }, 2000);
    },
  },
  mounted() {
    this.$bus.$on("showTips", this.showTips);
  },
};
</script>

<style lang="stylus" scoped>
.tips {
  max-width: 600px;
  padding: 10px 40px;
  border-radius: 4px;
  background-color: rgba(0, 0, 0, 0.2);
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);

  p {
    font-size: 16px;
    text-align: center;
    line-height: 20px;
    color: #fff;
  }
}
</style>